<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/18 0018
 * Time: 上午 10:24
 */

use cza\base\models\statics\OperationEvent;
use yii\helpers\Url;
use yii\widgets\Pjax;
use yii\helpers\Html;
use kartik\widgets\ActiveForm;
use kartik\builder\Form;
use cza\base\widgets\ui\adminlte2\InfoBox;
use cza\base\models\statics\EntityModelStatus;

$regularLangName = \Yii::$app->czaHelper->getRegularLangName();
$messageName = $model->getMessageName();
$activity = $model->entityModel->activity;

?>

<style>

    .mbox {
        display: flex;
        flex-wrap: wrap;
    }

    .box-item {
        width: 10%;
        padding: 5px;
        margin-left: 5px;
        background-color: white;
        cursor: pointer;
    }

    /*.box-item:active {*/
    /*border: solid 4px olivedrab;*/
    /*}*/

    /*.box-item:focus {*/
    /*border: solid 4px olivedrab;*/
    /*}*/

    /*.box-item:hover {*/
    /*border: solid 4px olivedrab;*/
    /*}*/


</style>

<?php Pjax::begin(['id' => $model->getDetailPjaxName(), 'formSelector' => $model->getBaseFormName(true), 'enablePushState' => false, 'clientOptions' => [
    'skipOuterContainers' => true
]]) ?>

<?php $js = "";
$js .= "jQuery('{$model->getDetailPjaxName(true)}').off('pjax:send').on('pjax:send', function(){jQuery.fn.czaTools('showLoading', {selector:'{$model->getDetailPjaxName(true)}', 'msg':''});});\n";
$js .= "jQuery('{$model->getDetailPjaxName(true)}').off('pjax:complete').on('pjax:complete', function(){jQuery.fn.czaTools('hideLoading', {selector:'{$model->getDetailPjaxName(true)}'});});\n";
$this->registerJs($js);
?>

<?php
$form = ActiveForm::begin([
    'action' => ['brush-vote', 'id' => $model->entityModel->id],
    'options' => [
        'id' => $model->getBaseFormName(),
        'data-pjax' => true,
        'style' => 'padding: 10px'
    ]]);
?>

<div class="<?= $model->getPrefixName('form') ?>">
    <?php if (Yii::$app->session->hasFlash($messageName)): ?>
        <?php if (!$model->hasErrors()) {
            echo InfoBox::widget([
                'withWrapper' => false,
                'messages' => Yii::$app->session->getFlash($messageName),
            ]);
            $model->entityModel->refresh();
            // $this->registerJs(
            //     "jQuery('{$model->getPrefixName('grid', true)}').trigger('" . OperationEvent::REFRESH . "');"
            // );
        } else {
            echo InfoBox::widget([
                'defaultMessageType' => InfoBox::TYPE_WARNING,
                'messages' => Yii::$app->session->getFlash($messageName),
            ]);
        }
        ?>
    <?php endif; ?>
    <p><?= $model->entityModel->title ?></p>

    <div class="row">
        <div class="col-xs-4">
            <img class="thumbnail" src="<?= $model->entityModel->getThumbnailUrl() ?>"/>
        </div>
        <div class="col-xs-8">
            <p><?= "当前免费票数：" . $model->entityModel->free_vote_number ?></p>
            <p><?= "当前礼物票数：" . $model->entityModel->gift_vote_number ?></p>
            <p><?= "当前总票数：" . $model->entityModel->total_vote_number ?></p>
        </div>
    </div>


    <div class="well mbox">

        <?php

        echo Form::widget([
            'model' => $model,
            'form' => $form,
            'columns' => 1,
            'attributes' => [
                'brush_sub_ids' => [
                    'type' => Form::INPUT_CHECKBOX_LIST,
                    'items' => $activity->getActivityGiftHashMap(),
                    'options' => [
                        'inline' => true
                        // 'items' => $activityModel->getActivityGiftHashMap(),
                        // 'items' => \common\models\c2\entity\GiftModel::getHashMap('id', 'name'),
                    ]
                ],
            ],
        ]);

        ?>
    </div>

    <div class="well">
        <?php

        echo Form::widget([
            'model' => $model,
            'form' => $form,
            'columns' => 2,
            'attributes' => [
                'user_id' => [
                    'type' => Form::INPUT_WIDGET,
                    'widgetClass' => \kartik\select2\Select2::className(),
                    'options' => [
                        'data' => ['' => 'Selecting...'] + \common\models\c2\entity\FeUserModel::getHashMap('id', 'username', [
                                'type' => \common\models\c2\statics\FeUserType::TYPE_SYS_REGISTRATION
                            ]),
                    ]
                ],
            ]
        ]);

        // echo $form->field($model, 'username', [
        //     'addon' => [
        //         'append' => [
        //
        //             'content' => Html::a('<i class="glyphicon glyphicon-repeat">' . Yii::t('app.c2', 'Reset User') . '</i>', Url::current(), [
        //                 'class' => 'btn btn-default',
        //                 'title' => Yii::t('app.c2', 'Reset Grid')
        //             ]),
        //             'asButton' => true
        //         ]
        //     ]
        // ])->textInput(['readonly' => true]);

        echo Html::beginTag('div', ['class' => 'box-footer']);
        echo Html::a('<i class="fa fa-window-close-o"></i> ' . Yii::t('app.c2', 'Close'), ['production'], ['data-pjax' => '0', 'data-dismiss' => 'modal', 'class' => 'btn btn-default', 'title' => Yii::t('app.c2', 'Go Back'),]);
        echo Html::submitButton('<i class="fa fa-save"></i> ' . Yii::t('app.c2', 'Save'), ['type' => 'button', 'class' => 'btn btn-primary']);
        echo Html::a('<i class="fa fa-refresh"></i>', Url::current(), ['type' => 'button', 'class' => 'btn btn-default']);
        echo Html::endTag('div');

        ?>
    </div>

</div>
<?php ActiveForm::end(); ?>

<?php Pjax::end() ?>
